package com.slowfly.rule.engine.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.slowfly.rule.engine.model.Flow;
import com.slowfly.rule.engine.model.Fuse;
import com.slowfly.rule.engine.typehandler.FlowListTypeHandler;
import com.slowfly.rule.engine.typehandler.JsonTypeHandler;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 策略实体类
 * </p>
 *
 * @author shalongfei
 * @since 2024-02-22
 */
@Getter
@Setter
@TableName(autoResultMap = true)
public class Strategy implements Serializable, Comparable<Strategy> {

    private static final long serialVersionUID = 1L;

    /**
     * 主键id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 场景id
     */
    private Integer sceneId;

    /**
     * 策略名称
     */
    private String name;

    /**
     * 优先级
     */
    private Integer priority;

    /**
     * 状态；1：下线，2：标记，3：上线，4：熔断
     */
    private Integer status;

    /**
     * 决策流
     */
    @TableField(typeHandler = FlowListTypeHandler.class)
    private List<Flow> flows;

    /**
     * 熔断
     */
    @TableField(typeHandler = JsonTypeHandler.class)
    private Fuse fuse;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    public int compareTo(Strategy strategy) {
        return this.priority - strategy.priority;
    }
}
